import 'dart:collection';

import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';
import 'package:finance_app/src/common/config.dart';

/// 角色权限
class HttpPermissionService {
  /// 获取公司角色信息
  static Future<Response> getAllRoles() {
    return BaseConfig.httpBase.get('/api/roles/company/roles', {});
  }

  /// 添加角色权限
  static Future<Response> addNewRole({String name, List permissions}) {
    return BaseConfig.httpBase.postJson(
        '/api/roles/company/roles', {"name": name, "items": permissions});
  }

  /// 添加角色权限
  static Future<Response> newRole() {
    return BaseConfig.httpBase.get('/api/roles/company/permissions', {});
  }

  /// 更新角色权限
  static Future<Response> editRole(int id, {String name, List permissions}) {
    return BaseConfig.httpBase.putJson('/api/roles/company/roles',
        {"id": id, "name": name, "items": permissions});
  }

  /// 删除角色权限
  static Future<Response> deleteRole(
    int id,
  ) {
    return BaseConfig.httpBase
        .deleteJson('/api/roles/company/roles', {"id": id});
  }

  /// 获取角色信息
  static Future<Response> getRoleDetails(int id) {
    return BaseConfig.httpBase.get('/api/roles/user/roles', {
      'id': id,
    });
  }

  /// 设定角色信息
  static Future<Response> setUserRoles(int roleId, String roleName,
      {List users}) {
    return BaseConfig.httpBase.postJson('/api/roles/user/roles', {
      'id': roleId,
      'name': roleName,
      'items': users,
    });
  }

  /// 获取自己的角色权限
  static Future<Response> getMyPermission() {
    return BaseConfig.httpBase.get('/api/roles/user/me/roles', {});
  }
}
